package com.showmaker.job;

import com.showmaker.constant.RedisConstant;
import com.showmaker.utils.QiNiuUtils;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.SetOperations;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.util.Set;

public class ClearPicJob extends QuartzJobBean {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    // 定义执行删除图片的任务
    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
//        SetOperations<String, String> operations = redisTemplate.opsForSet();
//        // 比较 redis 中的两个 set 集合，得到两个集合的差集
//        Set<String> difference = operations.difference(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
//        for (String picName : difference) {
//            // 删除七牛云服务器上的图片
//            QiNiuUtils.deleteFileFromQiniu(picName);
//            // 将 redis 集合中的图片名称也删除
//            operations.remove(RedisConstant.SETMEAL_PIC_RESOURCES, picName);
//        }
        System.out.println("图片清除任务完成");
    }
}
